{include file="pub/header"/}
<title>添加管理员</title>
</head>
<body>
<article class="page-container">
	<form class="form form-horizontal" id="form-admin-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户名：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="adminName" name="uname">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>管理员名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="name" name="name">
			</div>
		</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>初始密码：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="password" class="input-text" autocomplete="off" value="" placeholder="密码" id="password" name="password">
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>确认密码：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="password" class="input-text" autocomplete="off"  placeholder="确认新密码" id="password2" name="password2">
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色：</label>
		<div class="formControls col-xs-8 col-sm-9">
			{foreach $roleList as $key=>$role}
			<input type="checkbox" class="input-small" id="role-{$key}" value="{$key}" placeholder="" name="role_id[]">
			<label for="role-{$key}" class="">{$role}</label>
			{/foreach}
		</div>
	</div>
	<div class="row cl">
		<label class="form-label col-xs-4 col-sm-3">描述：</label>
		<div class="formControls col-xs-8 col-sm-9">
			<textarea name="describe" cols="" rows="" class="textarea"  placeholder="说点什么...100个字符以内" dragonfly="true"></textarea>
		</div>
	</div>
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
			<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
		</div>
	</div>
	</form>
</article>

{include file="pub/footer"/}

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript">
$(function(){
	$("#form-admin-add").validate({
		rules:{
			uname:{
				required:true,
				minlength:4,
				maxlength:10,
				remote: '{:url("Admin/checkName")}'
			},
			password:{
				required:true,
				minlength:6
			},
			password2:{
				required:true,
				equalTo: "#password"
			},
			"role_id[]":{
				required:true,
				minlength:2
			}
		},
		messages:{
			uname:{
			    required: '用户名不能为空',
				minlength: '最少不能少于4位',
				maxlength: '最多不能多余10位',
				remote: '用户名已存在'
			},
			password:{
			    required: '密码不能为空',
				minlength: '最少不能少于6位'
			},
			"role_id[]":{
			    required:'角色必须选择',
			    minlength:'至少选择一个角色'
			}
		},
		submitHandler:function(form){
			$(form).ajaxSubmit({
				type: 'post',
				url: "{:url('Admin/adminAdd')}" ,
				success: function(data){
				    if(1 == data.code){
                        var index = parent.layer.getFrameIndex(window.name);
                        layer.msg(data.msg, {icon:6, time:1000});
                        setTimeout(function(){
                            parent.location.reload();
                            parent.layer.close(index);
                        }, 1000);
                    }else{
				        layer.msg(data.msg, {icon:6, time:1000});
					}
                },
            error: function(XmlHttpRequest, textStatus, errorThrown){
                    layer.msg('error!',{icon:1,time:1000});
                }
        });
		}
	});
});
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>